home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gimp.idb / usr / freeware / include / libgimp / gimpmath.h.z / gimpmath.h
Encoding:
C/C++ Source or Header  |  2002-07-08  |  2.7 KB  |  110 lines

  1. /* LIBGIMP - The GIMP Library 
  2.  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
  3.  *
  4.  * gimpmath.h
  5.  *
  6.  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball                
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Lesser General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Lesser General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Lesser General Public
  19.  * License along with this library; if not, write to the
  20.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21.  * Boston, MA 02111-1307, USA.
  22.  */
  23.  
  24. #ifndef __GIMPMATH_H__
  25. #define __GIMPMATH_H__
  26.  
  27. #include <math.h>
  28.  
  29. #ifdef HAVE_IEEEFP_H
  30. #include <ieeefp.h>
  31. #endif
  32.  
  33. #ifdef G_OS_WIN32
  34. #include <float.h>
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif /* __cplusplus */
  40.  
  41.  
  42. /* Some portability enhancing stuff. For use both by the gimp app
  43.  * as well as plug-ins and modules.
  44.  *
  45.  * Include this instead of just <math.h>.
  46.  */
  47.  
  48. #ifndef G_PI            /* G_PI will be in GLib eventually */
  49. #define G_PI    3.14159265358979323846
  50. #endif
  51. #ifndef G_PI_2            /* As will G_PI_2 */
  52. #define G_PI_2  1.57079632679489661923
  53. #endif
  54. #ifndef G_PI_4            /* As will G_PI_4 */
  55. #define G_PI_4  0.78539816339744830962
  56. #endif
  57. #ifndef G_SQRT2            /* As will G_SQRT2 */
  58. #define G_SQRT2 1.4142135623730951
  59. #endif
  60.  
  61. #ifndef RAND_MAX
  62. #define G_MAXRAND G_MAXINT
  63. #else
  64. #define G_MAXRAND RAND_MAX
  65. #endif
  66.  
  67. /* Use RINT() instead of rint() */
  68. #ifdef HAVE_RINT
  69. #define RINT(x) rint(x)
  70. #else
  71. #define RINT(x) floor ((x) + 0.5)
  72. #endif
  73.  
  74. #define ROUND(x) ((int) ((x) + 0.5))
  75.  
  76. /* Square */
  77. #define SQR(x) ((x) * (x))
  78.  
  79. /* limit a (0->511) int to 255 */
  80. #define MAX255(a)  ((a) | (((a) & 256) - (((a) & 256) >> 8)))
  81.  
  82. /* clamp a >>int32<<-range int between 0 and 255 inclusive */
  83. /* broken! -> #define CLAMP0255(a)  ((a & 0xFFFFFF00)? (~(a>>31)) : a) */
  84. #define CLAMP0255(a)  CLAMP(a,0,255)
  85.  
  86. #define gimp_deg_to_rad(angle) ((angle) * (2.0 * G_PI) / 360.0)
  87. #define gimp_rad_to_deg(angle) ((angle) * 360.0 / (2.0 * G_PI))
  88.  
  89. #ifdef HAVE_FINITE
  90. #define FINITE(x) finite(x)
  91. #else
  92. #ifdef HAVE_ISFINITE
  93. #define FINITE(x) isfinite(x)
  94. #else
  95. #ifdef G_OS_WIN32
  96. #define FINITE(x) _finite(x)
  97. #else
  98. #ifdef __EMX__
  99. #define FINITE(x) isfinite(x)
  100. #endif /* __EMX__ */
  101. #endif /* G_OS_WIN32 */
  102. #endif /* HAVE_ISFINITE */
  103. #endif /* HAVE_FINITE */
  104.  
  105. #ifdef __cplusplus
  106. }
  107. #endif /* __cplusplus */
  108.  
  109. #endif /* __GIMPMATH_H__ */
  110.